package com.king.edu.controller;

import com.king.edu.pojo.BaseResponse;
import com.king.edu.service.ResumeService;
import com.king.edu.utils.SystemConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @ClassName: LoginController
 * @Description: TODO
 * @Author: wangchangyong
 * @Date: 2020/4/16 10:49
 * @Version: 1.0.0
 **/
@Controller
public class LoginController {

    @Autowired
    ResumeService resumeService;

    /**
     * 跳转登录页
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String toLoginPage() {
        return "login";
    }

    /**
     * 用户登录
     * @param username
     * @param password
     * @param session
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public BaseResponse toLoginPage(String username, String password, HttpSession session) {
        if (SystemConstant.USERNAME.equals(username) && SystemConstant.PASSWORD.equals(password)) {
            session.setAttribute(SystemConstant.USER_SESSION_KEY, username);
            return new BaseResponse("0000", "登录成功");
        } else {
            return new BaseResponse("0001", "用户名或密码错误！");
        }
    }

    /**
     * 跳转主页
     * @return
     */
    @RequestMapping(value = "/main", method = RequestMethod.GET)
    public String toMainPage(Map<String, Object> map) {
        map.put("content", resumeService.findAll());
        return "main";
    }

}
